[ Vue筆記 ] Vue使用setInterval


Posted by Akira on 2022-02-20

前言

最近在寫番茄鐘的Side project,在使用 setInterval 做計時器時,遇到了小小問題。
這邊紀錄一下解法。

範例

  data() {
    return {
      time: null,
    };
  },
  methods: {
    timer() {
      this.time = setInterval(
        function () {
        // 想重複的動作
        }.bind(this),
        200
      );
    },
    setTime() {
      this.timer();
    },
    stopTime() {
      if (this.time) {
        clearInterval(this.time);
        this.time = null;
      }
    },
}









Related Posts

Robot Framework之RIDE介面

Robot Framework之RIDE介面

透過網路交換資料的方式(SOAP 和 RESTful API)

透過網路交換資料的方式(SOAP 和 RESTful API)

請問 position: static, relative, absolute 跟 fixed 的差別是什麼?分別各舉一個會用到的場合

請問 position: static, relative, absolute 跟 fixed 的差別是什麼?分別各舉一個會用到的場合


Comments